<template>
  <view class="page-register">
    <image class="ui-img" src="../static/register.png" mode="aspectFit" />
    <button class="ui-btn" open-type="getUserInfo" lang="zh_CN" @getuserinfo="onGetUserInfo">授权</button>
  </view>
</template>

<script setup>
import { login } from "@/api";
import { onShow } from "@dcloudio/uni-app";
const onGetUserInfo = (e) => {
  uni.login({
    provider: "weixin",
    onlyAuthorize: true, // 微信登录仅请求授权认证
    success: function (event) {
      const { code } = event;

      console.log("code", code);
      //客户端成功获取授权临时票据（code）,向业务服务器发起登录请求。

      login({ code });

      // uni.setStorageSync("token", res.token);
    },
    fail: function (err) {
      // 登录授权失败
      // err.code是错误码
    },
  });
};


</script>

<style lang="scss">
.page-register {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  flex-direction: column;
  .ui-img {
    transform: translateY(-250rpx) scale(1.5);
    width: 100%;
    display: block;
  }
  .ui-btn {
    background: black;
    width: 80%;
    color: #fff;
  }
}
</style>
